package com.remoter.serialize.internal;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import com.remoter.basic.serialize.ISerialization;
import com.remoter.basic.util.ServiceLoader.MetaName;

/**
 * @author			koko
 * @date 			2017-08-08 14:27:39
 * @description 	类功能说明
 */
@MetaName("internal")
public class InternalSerialization implements ISerialization{

	@Override
	public void serialize(Object data, OutputStream outputStream, Class<?> type)throws IOException {
		try(ObjectOutputStream oos = new ObjectOutputStream(outputStream)){
			oos.writeObject(data);
		}
	}

	@Override
	public Object deserialize(InputStream inputStream, Class<?> type)throws IOException {
		try(ObjectInputStream ois = new ObjectInputStream(inputStream)){
			return ois.readObject();
		}catch(Exception e){
			throw new IOException(e.getMessage());
		}
	}
	
}